package com.fafa.tankgame02;

import static java.lang.Thread.sleep;

/**
 * 射击子弹
 */
public class Shot implements Runnable {
    public int x; //子弹的x坐标
    public int y; //子弹的y坐标
    public int direct = 0; //方向
    public int speed = 10;
    public boolean isLive = true; //是否存在

    Shot(int x, int y, int direct) {
        this.x=x;
        this.y=y;
        this.direct = direct;
    }

    @Override
    public void run() {
        while (true) {
            try {
                sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            switch (direct) {
                case 0:
                    y -= speed;
                    break;
                case 1:
                    y += speed;
                    break;
                case 2:
                    x -= speed;
                    break;
                case 3:
                    x += speed;
                    break;
                default:
                    break;
            }
            //碰到边界
            if(!(x >= 0 && x <=1000 && y>=0&& y <=750))
            {
                isLive = false;
                break;
            }
            //System.out.println(direct + "子弹 x= " + x + " y= " + y);
        }

    }
}
